<template>
  <div class="tab-title-page">
    <div class="common_form_search">
      <el-form ref="searchForm" :inline="true" :model="searchForm">
        <el-form-item label="供应商名称">
          <el-input v-model="searchForm.shopName" placeholder="请输入供应商名称" clearable />
        </el-form-item>
        <el-form-item label="收款人姓名">
          <el-input v-model="searchForm.payeeName" placeholder="请输入收款人姓名" clearable />
        </el-form-item>
        <el-form-item label="支付宝账号">
          <el-input v-model="searchForm.payeeAccount" placeholder="请输入支付宝账号" clearable />
        </el-form-item>
        <!-- <el-form-item label="提现状态">
          <el-select
            v-model="searchForm.status"
            placeholder="全部"
            clearable
          >
            <el-option
              label="待审核"
              :value="1"
            ></el-option>
            <el-option
              label="已提现"
              :value="2"
            ></el-option>
            <el-option
              label="提现拒绝"
              :value="3"
            ></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="申请时间">
          <my-date-picker ref="myDatePicker1" />
        </el-form-item>
        <el-form-item label="入账时间">
          <my-date-picker ref="myDatePicker2" />
        </el-form-item>
        <el-form-item>
          <el-button size="small" type="primary" @click="search()">查询</el-button>
          <el-button size="small" @click="reset()">重置</el-button>
        </el-form-item>
      </el-form>
      <el-divider />
      <el-tabs v-model="activeName" class="flex-1 nav_tabs" @tab-click="handleClick">
        <el-tab-pane :label="`全部(${count.all || 0})`" name="all" />
        <el-tab-pane :label="`待审核(${count['1'] || 0})`" name="1" />
        <el-tab-pane :label="`已入账(${count['2'] || 0})`" name="2" />
        <el-tab-pane :label="`未入账(${count['3'] || 0})`" name="3" />
        <el-tab-pane :label="`提现拒绝(${count['4'] || 0})`" name="4" />
      </el-tabs>
    </div>
    <el-divider class="middle_divider" />
    <div class="child_page">
      <div class="flex align-center table-top-btns">
        <h5 class="flex align-center">
          <svg-icon style="margin-right: 15px" icon-class="list" :size="15" />数据列表
        </h5>
        <el-button v-if="$hasMethod('#export')" size="small" class="export-btn" icon="el-icon-upload2" @click="exportFile">导出</el-button>
      </div>
      <el-table border :data="tableData">
        <el-table-column fixed width="60" align="center" prop="id" label="编号" />
        <el-table-column align="center" label="账户类型">
			<template slot-scope="scope">
			  <span>{{ scope.row.member_id ? "租金账户" : "推广账户" }}</span>
			</template>
        </el-table-column>
        <el-table-column align="center" label="供应商名称">
			<template slot-scope="scope">
			  <span>{{ scope.row.member_id ? scope.row.shopname : "推广-"+scope.row.sale_user_id }}</span>
			</template>
        </el-table-column>
        <el-table-column align="center" label="提现方式">
          <template slot-scope="scope">
            <span>{{ scope.row.pay_type == 1 ? "支付宝" : "" }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="withdrawal_amount" label="提现金额" />
        <el-table-column align="center" prop="payee_account" label="支付宝账户" />
        <el-table-column align="center" prop="payee_name" label="收款人姓名" />
        <el-table-column align="center" prop="apply_time" label="申请时间" width="100" />
        <el-table-column align="center" prop="arrival_time" label="入账时间" width="100" />
        <el-table-column align="center" label="提现状态" width="100">
          <template slot-scope="scope">
            <el-tag :type="scope.row.status == 1 ? '' : scope.row.status == 2 || scope.row.status == 3 ? 'success' : 'danger'">
              {{ scope.row.status == 1 ? "待审核" : scope.row.status == 2 ? "已入账" : scope.row.status == 3 ? "未入账" : "提现拒绝" }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="refuse_reason" label="原因" width="180" />
        <el-table-column align="center" prop="check_time" label="审核时间" width="100" />
        <el-table-column align="center" prop="admin_name" label="操作人" />
        <el-table-column fixed="right" align="center" label="操作" width="130px">
          <template slot-scope="scope">
            <el-button v-if="scope.row.status == 1 && $hasMethod('#pass')" type="warning" size="mini" @click="pass(scope.row.id)">同意</el-button>
            <el-button v-if="scope.row.status == 1 && $hasMethod('#refuse')" type="danger" size="mini" @click="refuse(scope.row.id)">拒绝</el-button>
          </template>
        </el-table-column>
      </el-table>
      <custom-page ref="customPage" :total="total" @getList="getList" />
    </div>
    <pass-dialog ref="passDialog" :edit-id="selectedId" @getList="getList" />
    <refuse-dialog ref="refuseDialog" :edit-id="selectedId" @getList="getList" />
  </div>
</template>

<script>
import customPage from '@/components/customPage'
import myDatePicker from '@/components/myDatePicker'
import {
  withdrawalExamineList,
  withdrawalExamineListExport,
  withdrawalPass,
} from '@/api/audit'
import passDialog from './pass'
import refuseDialog from './refuse'
export default {
  components: { customPage, myDatePicker, passDialog, refuseDialog },
  data() {
    return {
      searchForm: {
        shopName: '',
        payeeName: '',
        payeeAccount: '',
        status: '',
        applyTime: '',
        arrivalTime: ''
      },
      tableData: [],
      total: 0,
      count: {},
      activeName: 'all',
      selectedId: ''
    }
  },
  methods: {
    refuse(id) {
      this.selectedId = id
      this.$refs.refuseDialog.dialogVisible = true
    },
    pass(id) {
      // this.selectedId = id;
      // this.$refs.passDialog.dialogVisible = true;
      const that = this;
      this.$confirm('确定同意提现审核吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      })
        .then(() => {
          withdrawalPass({ id }).then((res) => {
            if (res) {
              that.getList(true)
            }
          })
        })
        .catch(() => { })
    },
    handleClick(tab) {
      this.activeName = tab.name
      this.$refs.customPage.page = 1
      this.getList()
    },
    // 获取数据
    getList() {
      // flag为true, 则不刷新表格
      const { page, pageSize } = this.$refs.customPage;
      this.searchForm.status = this.activeName === 'all' ? '' : this.activeName
      withdrawalExamineList({
        page,
        pageSize,
        ...this.searchForm
      }).then((res) => {
        const {
          list: { data, total },
          count
        } = res
        this.tableData = data || []
        this.total = total || 0
        let obj = {}
        if (this.activeName === 'all') {
          count.forEach((element) => {
            obj[element.status] = element.count || 0
          });
          this.count = obj
        }
      })
    },
    // 查询
    search() {
      const pickerVal1 = this.$refs.myDatePicker1.getVal()
      const pickerVal2 = this.$refs.myDatePicker2.getVal()
      if (pickerVal1 !== "error" || pickerVal2 !== "error") {
        this.searchForm.applyTime = pickerVal1
        this.searchForm.arrivalTime = pickerVal2
        this.$refs.customPage.page = 1
        this.getList()
      }
    },
    // 重置
    reset() {
      if (this.$refs.myDatePicker1) {
        this.$refs.myDatePicker1.reset()
      }
      if (this.$refs.myDatePicker2) {
        this.$refs.myDatePicker2.reset()
      }
      this.searchForm = {
        shopName: '',
        payeeName: '',
        payeeAccount: '',
        status: '',
        applyTime: '',
        arrivalTime: ''
      };
      this.getList()
    },
    exportFile() {
      withdrawalExamineListExport(this.searchForm)
    }
  },
  mounted() {
    this.getList()
  }
}
</script>

<style lang="scss" scoped>
.common_form_search {
  padding: 15px 15px 0 15px;
  background-color: #ffffff;
  border-radius: 0 0 10px 10px;
}

.child_page {
  padding: 15px;
}

/deep/.el-divider--horizontal {
  margin: 0;
}
</style>
